package com.newjiabo.ski.service.impl;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.newjiabo.common.utils.DateUtils;
import com.newjiabo.common.utils.SnowFlake;
import com.newjiabo.common.utils.StringUtils;
import com.newjiabo.ski.domain.SkiMoreServices;
import com.newjiabo.ski.domain.dto.MoreServicesDTO;
import com.newjiabo.ski.domain.dto.SkiSnowFieldDTO;
import com.newjiabo.ski.mapper.SkiMoreServicesMapper;
import com.newjiabo.ski.service.ISkiMoreServicesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 更多服务Service业务层处理
 *
 * @author CaoMengHui
 * @date 2023-09-19
 */
@Service
public class SkiMoreServicesServiceImpl implements ISkiMoreServicesService {
    @Resource
    private SkiMoreServicesMapper skiMoreServicesMapper;

    /**
     * 查询更多服务
     *
     * @param servicesId 更多服务主键
     * @return 更多服务
     */
    @Override
    public SkiMoreServices selectSkiMoreServicesByServicesId(String servicesId) {
        return skiMoreServicesMapper.selectSkiMoreServicesByServicesId(servicesId);
    }

    /**
     * 查询更多服务列表
     *
     * @param skiMoreServices 更多服务
     * @return 更多服务
     */
    @Override
    public List<SkiMoreServices> selectSkiMoreServicesList(SkiMoreServices skiMoreServices) {
        return skiMoreServicesMapper.selectSkiMoreServicesList(skiMoreServices);
    }

    /**
     * 新增更多服务
     *
     * @param skiMoreServices 更多服务
     * @return 结果
     */
    @Override
    public int insertSkiMoreServices(SkiMoreServices skiMoreServices) {
        if (StringUtils.isEmpty(skiMoreServices.getServicesId())) {
            skiMoreServices.setServicesId(SnowFlake.getIdStr());
        }
        skiMoreServices.setCreateTime(DateUtils.getNowDate());
        skiMoreServices.setDelFlag(false);
        return skiMoreServicesMapper.insertSkiMoreServices(skiMoreServices);
    }

    /**
     * 修改更多服务
     *
     * @param skiMoreServices 更多服务
     * @return 结果
     */
    @Override
    public int updateSkiMoreServices(SkiMoreServices skiMoreServices) {
        skiMoreServices.setUpdateTime(DateUtils.getNowDate());
        return skiMoreServicesMapper.updateSkiMoreServices(skiMoreServices);
    }

    /**
     * 批量删除更多服务
     *
     * @param servicesIds 需要删除的更多服务主键
     * @return 结果
     */
    @Override
    public int deleteSkiMoreServicesByServicesIds(String[] servicesIds) {
        return skiMoreServicesMapper.deleteSkiMoreServicesByServicesIds(servicesIds);
    }

    /**
     * 删除更多服务信息
     *
     * @param servicesId 更多服务主键
     * @return 结果
     */
    @Override
    public int deleteSkiMoreServicesByServicesId(String servicesId) {
        return skiMoreServicesMapper.deleteSkiMoreServicesByServicesId(servicesId);
    }

    @Override
    public List<SkiMoreServices> getAll() {
        return skiMoreServicesMapper.getAll();
    }

    @Override
    public int addMoreServices(MoreServicesDTO dto) {
        this.initMoreServices(dto);
        SkiMoreServices skiMoreServices = BeanUtil.copyProperties(dto, SkiMoreServices.class);
        return this.insertSkiMoreServices(skiMoreServices);
    }

    @Override
    public int updateMoreServices(String moreServicesId, MoreServicesDTO dto) {
        this.initMoreServices(dto);
        SkiMoreServices skiMoreServices = BeanUtil.copyProperties(dto, SkiMoreServices.class);
        skiMoreServices.setServicesId(moreServicesId);
        return this.updateSkiMoreServices(skiMoreServices);
    }

    @Override
    public List<SkiMoreServices> selectInIds(List<String> ids) {
        return skiMoreServicesMapper.selectInIds(ids);
    }

    @Override
    public List<SkiMoreServices> getBySetMealId(String setMealId, boolean status) {
        return skiMoreServicesMapper.getBySetMealIdAndStatus(setMealId,status);
    }

    private void initMoreServices(MoreServicesDTO dto) {
        if(ObjectUtil.isNull(dto.getStatus())){
            dto.setStatus(true);
        }
    }
}
